package com.llkj.qingnianguoxue.adapter;

import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.llkj.qingnianguoxue.R;
import com.llkj.qingnianguoxue.bean.MasterDataBean;
import com.llkj.qingnianguoxue.util.DisplayUtil;
import com.llkj.qingnianguoxue.util.ImageLoadingUtil;
import com.llkj.qingnianguoxue.util.StringUtils;

import java.util.List;

/**
 * 大师适配器
 */
public class MasterAdapter extends BaseQuickAdapter<MasterDataBean.MasterBean, BaseViewHolder> {

    public MasterAdapter(int layoutResId, List<MasterDataBean.MasterBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, MasterDataBean.MasterBean item) {
        ImageView ivHead = baseViewHolder.getView(R.id.iv_head);
        ImageLoadingUtil.loadImgGlideRoundCenterCrop(ivHead, item.getImg());
        RelativeLayout.LayoutParams ivParam = (RelativeLayout.LayoutParams) ivHead.getLayoutParams();
        ivParam.width = DisplayUtil.dip2px(mContext,80)*16/9;
        ivHead.setScaleType(ImageView.ScaleType.CENTER_CROP);

        baseViewHolder.setText(R.id.tv_title, item.getName());
        baseViewHolder.setText(R.id.tv_introduction, item.getAbstractX());
//        if (1 == item.getIs_buy()) {// 是 1否 2购买
//            baseViewHolder.setText(R.id.tv_price, "已订阅");
//        } else {
        if(!StringUtils.isEmpty(item.getPrice())){
            baseViewHolder.setText(R.id.tv_price, "￥" + item.getPrice() + "银子");
        }else{
            baseViewHolder.setText(R.id.tv_price, "" );
        }

//        }

        if(!StringUtils.isEmpty(item.getOrder_num())){
            String count = item.getOrder_num() + "人订阅";
//        SpannableString sp = TextViewUtil.getForegroundColorSpan(mContext, count, 0, item.getOrder_num().length(), mContext.getResources().getColor(R.color.colorC49F4A));
            baseViewHolder.setText(R.id.tv_buy_count, count);
        }else{
            baseViewHolder.setText(R.id.tv_buy_count, "");
        }

    }

}
